package com.kaiyiweitong.tongxing.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.kaiyiweitong.tongxing.R;

/**
 * Created by Administrator on 2017/12/21 0021.
 */

public class FinishedAdapter extends RecyclerView.Adapter {

    private Context mContext;
    private final LayoutInflater mInflater;
    private OnClickListener mListener;

    public interface OnClickListener {
        void reqBillClick(int position);

        void afterSellClick(int position);

        void evaluateClick(int position);
    }

    public FinishedAdapter(Context context, OnClickListener listener) {
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mListener = listener;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_finished, null);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        MyViewHolder viewHolder = (MyViewHolder) holder;

        viewHolder.req_bill.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.reqBillClick(position);
            }
        });

        viewHolder.req_after_sell.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.afterSellClick(position);
            }
        });

        viewHolder.evaluate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.evaluateClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return 10;
    }

    private class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView order_num;
        private ImageView pic;
        private TextView title;
        private TextView content;
        private TextView req_bill;
        private TextView req_after_sell;
        private TextView evaluate;


        public MyViewHolder(View itemView) {
            super(itemView);
            order_num = itemView.findViewById(R.id.order_name);
            pic = itemView.findViewById(R.id.pic);
            title = itemView.findViewById(R.id.title);
            content = itemView.findViewById(R.id.content);
            req_bill = itemView.findViewById(R.id.req_bill);
            req_after_sell = itemView.findViewById(R.id.req_after_sell);
            evaluate = itemView.findViewById(R.id.evaluate);

        }
    }
}
